﻿@model MvcLuceneSampleApp.ViewModels.IndexViewModel

<div class="content_left">
  <span style="color: green;">@TempData["Result"]</span>
  <span style="color: red;">@TempData["ResultFail"]</span>
</div>
<div class="clear"></div>

<div class="col_12">		
  <fieldset>
	  <legend>(@Html.ActionLink("Create Index", "CreateIndex"))</legend> 
	  <table class="grid">
		  <tr>
			  <th>@Html.LabelFor(m => Model.SampleData.Id)</th>
			  <th>@Html.LabelFor(m => Model.SampleData.Name)</th>
			  <th>@Html.LabelFor(m => Model.SampleData.Description)</th>
		  </tr>
	  @foreach (var record in Model.AllSampleData) {
		  <tr>
			  <td>@record.Id</td>
			  <td>@record.Name</td>
			  <td>@record.Description</td>
		  </tr>
	  }		
	  </table>	
    
    @if (ViewBag.Limit > 0) {
      <div class="margin_top10">And <b>@ViewBag.Limit</b> more records... (<a href="\?limit=0">See All</a>)</div>
    }
  </fieldset>
</div>

<div class="col_12">
  <fieldset>
	  <legend>Search</legend>
    <div class="content_left margin_top5">
	    <p></p>
    </div>
    @using (Html.BeginForm("Search", "Home")) {
      <div class="content_left margin_top13 margin_left30" style="display:none">
        @Html.CheckBoxFor(m => m.SearchDefault)
        @Html.LabelFor(m => m.SearchDefault, "Use default Lucene query")
      </div>
	    <div class="content_left margin_right20">
		    @Html.TextBoxFor(m => m.SearchTerm, new { @class="big", style="width:650px;", autocomplete="off" })
      </div>
      <div class="content_left margin_top15 margin_right30" style="display:none">
		    @Html.DropDownListFor(m => m.SearchField, Model.SearchFieldList.Select(x => new SelectListItem { Text = x.Text, Value = x.Value }),
          new { style="width:150px;" })
      </div>
      <div class="content_right margin_top8">
		    <input type="submit" value="Search" />
      </div>
      <div class="clear"></div>
	  }
  </fieldset>
</div>
		
<div class="col_8">
  <fieldset>
	  <legend>
		  Search index
		  (@Html.ActionLink("Clear Index", "ClearIndex"))
	  </legend> 
    
    @if (Model.SearchIndexData.Any()) {
      <table class="grid">
        <tr>
          <th>@Html.LabelFor(m => Model.SampleData.Id)</th>
          <th>@Html.LabelFor(m => Model.SampleData.Name)</th>
          <th>@Html.LabelFor(m => Model.SampleData.Description)</th>
          <th></th>
        </tr>
        @foreach (var record in Model.SearchIndexData) {
          <tr>
            <td>@record.Id</td>
            <td>@record.Name</td>
            <td>@record.Description</td>
            <td>@Html.ActionLink("Delete", "ClearIndexRecord", new {record.Id})</td>
          </tr>
        }		
      </table>
    } else {
      <text><br/>No search index records found...<br/></text>
    }
  </fieldset>
</div>

<div class="col_4">
</div>

<script type="text/javascript">
	$(document).ready(function () {
		$('#SearchTerm').focus();
		$('.grid tr:even').css("background", "silver");
	});

</script>